package implementation1.data;

import interfaces.app.IStream;
import interfaces.data.IAccount;
import interfaces.data.IHandle;

/**
 * Standard handle, which contains data for initialization commands and their processes.
 *
 * @author Jan Svab
 *         Created 15.10.11
 */
public class Handle implements IHandle
{
    /**
     * Parameters of handle
     */
    private String[] parameters;
    /**
     * Input stream
     */
    private IStream streamIn;
    /**
     * Output stream
     */
    private IStream streamOut;
    /**
     * Output stream for errors
     */
    private IStream streamErrorOut;
    /**
     * Name of command
     */
    private String commandName;
    /**
     * Actual path
     */
    private String actualPath;
    /**
     * Account of user which owns process.
     */
    private IAccount account;

    /**
     * Default constructor.
     *
     * @param parameters  parameters of handle
     * @param in          input stream
     * @param out         output stream
     * @param errorOut    output stream for errors
     * @param commandName name of command
     * @param actualPath  actual directory
     * @param account     account of user which owns process
     */
    public Handle(String[] parameters, IStream in, IStream out, IStream errorOut,
                  String commandName, String actualPath, IAccount account)
    {
        this.parameters = parameters;
        this.streamIn = in;
        this.streamOut = out;
        this.streamErrorOut = errorOut;
        this.commandName = commandName;
        this.actualPath = actualPath;
        this.account = account;
    }

    /**
     * Return an array of param.
     *
     * @return the array of params
     */
    @Override
    public String[] getParams()
    {
        if (parameters == null)
        {
            return new String[0];
        }

        return parameters;
    }

    /**
     * Return a stream for input.
     *
     * @return the input stream
     */
    @Override
    public IStream getIn()
    {
        return streamIn;
    }

    /**
     * Return a stream for output.
     *
     * @return the output stream
     */
    @Override
    public IStream getOut()
    {
        return streamOut;
    }

    /**
     * Return a stream for error output.
     *
     * @return the error output stream
     */
    @Override
    public IStream getErrorOut()
    {
        return streamErrorOut;
    }

    /**
     * Return a name of command.
     *
     * @return the name of command
     */
    @Override
    public String getCommandName()
    {
        return commandName;
    }

    /**
     * Return an actual absolute path in filesystem.
     *
     * @return the actual absolute path in filesystem
     */
    @Override
    public String getActualPath()
    {
        return actualPath;
    }

    /**
     * Return an account of logged user.
     *
     * @return the account of logged user
     */
    @Override
    public IAccount getAccount()
    {
        return account;
    }

    /**
     * Sets new current directory.
     *
     * @param newPath Path to new directory
     */
    @Override
    public void setActualPath(String newPath)
    {
        actualPath = newPath;
    }
}
